#pragma once
#include <iostream>
#include <cstdarg>
#include <ctime>

enum level
{
    DEBUG,
    NORMAL,
    WARNING,
    ERROR,
    FATAL
};

const char *level_map[] = {
    "DEBUG",
    "NORMAL",
    "WARNING",
    "ERROR",
    "FATAL"};

void logMessage(int level, const char *format, ...)
{
    time_t t = time(nullptr);
    struct tm *tv = localtime(&t);

    // #标准部分
    char stdbuffer[1024];
    snprintf(stdbuffer, sizeof(stdbuffer), "[%s] [%d年%02d月%02d日 %02d:%02d:%02d] ", level_map[level],
             1900 + tv->tm_year, 1 + tv->tm_mon, tv->tm_mday, //年月日
             tv->tm_hour, tv->tm_min, tv->tm_sec); //时分秒

    // #自定义部分
    va_list ap;
    char buffer[10240];
    va_start(ap, format);
    vsnprintf(buffer, sizeof(buffer), format, ap);
    printf("%s %s\n", stdbuffer, buffer);
    va_end(ap);
}
